layui.config({
    base: "/static/backend/js/"
}).use(['form', 'layer', 'jquery', 'table', 'laydate'], function () {
    var laydate = layui.laydate;
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        table = layui.table,
        $ = layui.jquery;


    //第一个实例
    table.render({
        elem: '#list'
        ,toolbar: '#toolbar'
        , height: 'full-10'
        , url: '/backend/goods_order/dolist' //数据接口
        , page: true //开启分页
        , cols: [[ //表头
            { field: 'order_id', title: 'ID',}
            , { field: 'order_number', title: '订单号', }
            , { field: 'userid', title: '买家ID',  }
            , { field: 'nickname', title: '买家昵称',  }
            , { field: 'name', title: '商品名称', }
            , { field: 'tprice', title: '总价',}
            , { field: 'status1', title: '状态',  }
            ,{title: '操作',toolbar: '#barDemo'}
        ]]
    });





    table.on('tool(user)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        if(layEvent === 'details') {
            
            layui.layer.open({
                title : "商品详情",
                type : 2,
                area: ['75%', '75%'],
                offset: ['', '18%'],
                content : "/backend/goods_order/oder_date/order_id/"+data.order_id,
                success : function(layero, index){
                }
            })

        }
        });

    $('.search_btn').click(function () {
        var order_number= $('.searchVal').val();
        var order_status= $('#status').val();
        table.reload('list', {
            url: '/backend/goods_order/dolist'
            ,where: {order_number:order_number,status:order_status} //设定异步数据接口的额外参数

        });

    })
    $('#submit').click(function () {
        layer.confirm('确定取消订单？', function(index){
            layer.close(index);
           $('#submit').css('display','none');
           $('#reason_textarea').css('display','block');
           $('#submit1').css('display','block');
        });
    })
    $('#submit1').click(function () {
         var order_id = $("input[name='order_id']").val();
         var reason = $("textarea[name='reason']").val();
        if(reason == ''){
            top.layer.msg("请填写原因");return;
        }
         $.post('/backend/goods_order/cancel_order', {
         order_id: order_id,reason:reason
         }, function (data) {
         if (data.code == 0) {
         top.layer.msg(data.msg);
             parent.location.reload()
         } else {
         top.layer.msg("出错了！！！");
         }

         }
         );
    });

})